package com.huan.servlet;

import com.huan.service.NewsService;
import com.huan.service.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servlet/doDel")
public class NewDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //防止乱码
        NewsService newsDetailService = new NewsServiceImpl();
        String deleteId = request.getParameter("deleteId");
        Integer deleteID=null;
        if(deleteId!=null && !"".equals(deleteId)){
            deleteID=Integer.valueOf(deleteId);
            newsDetailService.deleteNews(deleteID);
            request.getRequestDispatcher("/pages/admin/newsDetailList.jsp").forward(request,response);
        }else {
            String err="删除失败！";
            request.setAttribute("err",err);
            request.getRequestDispatcher("/pages/admin/newsDetailList.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
